package com.hyb.controller;

import com.hyb.pojo.User;
import com.hyb.service.UserService;
import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;


import javax.annotation.Resource;

import javax.servlet.http.HttpSession;


@Controller
public class LoginController {
    @Resource
    UserService userService;

    @RequestMapping("/user/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/tologin")
    public String login(String username, String pwd, HttpSession session, ModelMap map) {
        User user = userService.getUserByName(username);
        if (!StringUtils.isEmpty(username)&&user.getPwd().equals(pwd)){
            session.setAttribute("loginUser",user);
            map.put("user",user);
            return "index";
        }else{
            map.put("msg","用户名或密码错误");
            return "login";
        }
    }
}
